package com.wrench.test;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import net.sf.json.JSONObject;

import org.junit.Test;

import com.cellplus.comm.util.ImpBeanUtil;
import com.cellplus.comm.util.ImpCommUtil;
import com.cellplus.comm.util.ImpJsonUtil;
import com.ydd.wrench.bean.base.TableData;
import com.ydd.wrench.form.reqresp.ReqInitNewInfo;
import com.ydd.wrench.form.reqresp.ReqResTableData;

public class templatereflect {
	public List<String> list = new LinkedList<String>();
	@SuppressWarnings("unused")
	public static void main(String[] args) throws Exception {
		ReqInitNewInfo p1 = new ReqInitNewInfo();

		p1.dbConn = "232";
		p1.localPath = "fff";

		ArrayList<Object> list = new ArrayList<Object>();

		Method m1 = list.getClass().getMethod("add", Object.class);
		m1.invoke(list, p1);

		ImpCommUtil.Out(list.toString());
		
		Class<?> zzClass = templatereflect.class.getField("list").getType();
		if ( zzClass == List.class ){
			int aa = 100;
		}
		if ( zzClass.getGenericSuperclass() instanceof ParameterizedType ){
			int aa = 100;
		}

		ParameterizedType pt = (ParameterizedType) templatereflect.class.getField("list").getGenericType();
		System.out.println(pt.getActualTypeArguments().length);
		System.out.println(pt.getActualTypeArguments()[0]);
	}
	
	
	@Test
	public void doReflectListT(){
		
		TableData item = new TableData();
		
		ReqResTableData data = new ReqResTableData();
		data.tableArr.add(item);
				
		JSONObject jobj = ImpBeanUtil.objOrMapToJson( data,  null);
		ImpCommUtil.Out(jobj.toString());
		
		//TableDatasInfo dd = (TableDatasInfo) JSONObject.toBean(jobj, TableDatasInfo.class, TableDatasInfo.getClassMap());
		ReqResTableData dd = ImpJsonUtil.objFromJson2(jobj, null, ReqResTableData.class, null, ReqResTableData.getClassMap(),null);		
		ImpCommUtil.Out(dd.toString());
	}
	
}
